﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Ink;

namespace WP7Paint
{
    public partial class MainPage : PhoneApplicationPage
    {
        Stroke NewStroke;
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            SetBoundary();
        }

        private void SetBoundary()
        {
            RectangleGeometry boardGeometry = new RectangleGeometry();
            boardGeometry.Rect = new Rect(0, 0, Board.ActualWidth, Board.ActualHeight);
        }

        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }
        }

        private void Board_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {           
            Board.CaptureMouse();
            StylusPointCollection MyStylusPointCollection = new StylusPointCollection();
            MyStylusPointCollection.Add(e.StylusDevice.GetStylusPoints(Board));
            NewStroke = new Stroke(MyStylusPointCollection);
            NewStroke.DrawingAttributes.Color = Colors.Green;
            Board.Strokes.Add(NewStroke);

        }

        private void Board_MouseMove(object sender, MouseEventArgs e)
        {
        if (NewStroke != null)
        NewStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(Board));
}

        private void Board_LostMouseCapture(object sender, MouseEventArgs e)
        {
            NewStroke = null;
        }

      
    }
}